package com.ruoyi.front.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.front.domain.Account;
import com.ruoyi.front.dto.PassDTO;
import com.ruoyi.front.service.AccountService;
import com.ruoyi.front.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("front")
public class AccountController {
    @Autowired
    private AccountService accountService;
    //用户登录
    @PostMapping("login")
    public R login(@RequestBody Account account){
        String username = account.getUsername();
        String password = account.getPassword();
        return accountService.login(username,password);
    }
    @PutMapping("updatePass")
    public R updatePass(@RequestBody PassDTO passDTO, HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("token");
        System.out.println("oldPass = " + passDTO.getOldPass() + ", newPass = " + passDTO.getNewPass());
        return accountService.updatePass(passDTO,token);
    }
}
